package jmine.tec.persist.hibernate.proxy;

import jmine.tec.persist.hibernate.initializer.ProxyInitializer;
import jmine.tec.utils.spring.BeanReference;

import org.hibernate.engine.SessionImplementor;
import org.hibernate.proxy.HibernateProxy;

/** 
 * Implementação de {@link AbstractPojoProxy} para trabalhar com o {@link ProxyInitializer}.
 * 
 * @author wellington.santos
 * @created May 30, 2012
 */
public class LazyPojoProxy extends AbstractPojoProxy {

    protected BeanReference<? extends ProxyInitializer> proxyInitializerReference;

    /**
     * Construtor.
     *
     * @param initializerReference {@link ProxyInitializer}
     * @param sessionReference sessão do hibernate
     * @param impl objeto "lazy" a encapsular
     */
    public LazyPojoProxy(BeanReference<? extends ProxyInitializer> initializerReference, BeanReference<? extends SessionImplementor> sessionReference,
            HibernateProxy impl) {
        super(sessionReference, impl);
        this.proxyInitializerReference = initializerReference;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void onInitialized(Object object) {
        this.proxyInitializerReference.get().initialize(object);
    }

}
